<?php
/**
 * Created by PhpStorm.
 * User: kkw
 * Date: 2019/1/29
 * Time: 15:36
 */
namespace kkw\goods\response;
use kkw\user\Util;
use kkw\goods\table\GoodsTable;
use suda\core\Request;
use suda\core\Response;


class GoodsListResponse extends  Response
{

    public function onRequest(Request $request)
    {
        Util::printHeader();


        $goods_table= new GoodsTable();

//        $json = Request::json();
//        $pageSize = $json['pageSize'];


        // 设置每页的数量

        try {
//            $count = $goods_table->count();
//
//            // 总页数
//            $pageNumber = $count /$pageSize;
//            // 查询数据
            $goodslist = $goods_table->list();

        } catch (\suda\exception\SQLException $e) {
            $this->json(['code'=>$e->getCode(), 'message'=>'请求商品数据失败']);
            return;
        }
        $this->json([
            'code'=> 0,
//            'total'=>$count,
            'data'=> $goodslist,
            'message'=> '请求数据成功'
        ]);
    }
}